// pages/wuliurongqiguanli/nav_check_gzcbl/check_gzcbl.js
const baseUrl = "https://logisticsengineering.gree.com/container_manage_api/container_manage/"
const mybehavior = require("../../../../../../behaviors/requests")
import WxValidate from "../../../../../../Wx_Validate/WxValidate"

Page({

  /**
   * 页面的初始数据
   */
  behaviors: [mybehavior],
  data: {
    config_obj: {
      举报后待责任单位确认: ["责任单位已确认，待整改", "待公司管理员确定责任单位", "完结-责任单位已确认，作为月度考评数据",],//1.确定（是/否整改）2.申诉
      公司管理员判定所属责任单位待责任单位确认: ["责任单位已确认，待整改", "完结-责任单位已确认，作为月度考评数据",],//
      待公司管理员确定责任单位: ["待举报人修正数据或取消", "公司管理员判定所属责任单位，待责任单位确认"],
      责任单位已确认待整改: ["第1次整改完成，待举报人确认", "完结-整改未完成，作为月度考评数据"],//1，报完工2.未完成
      第1次整改完成待举报人确认: ["第1次整改完成，举报人不认可，待重新整改", "待公司管理员确认是否考核"],//1.驳回 2.完工
      第1次整改完成举报人不认可待重新整改: ["第1次整改结果有争议，待公司管理员判定", "责任单位已确认，待第2次整改"],
      第2次整改完成待举报人确认: ["待公司管理员确认是否考核", "待公司管理员确认是否考核"],
      第1次整改结果有争议待公司管理员判定: ["完结-管理员认定考核", "完结-管理员取消考核"],
      待公司管理员确认是否考核: ["完结-管理员认定考核", "完结-管理员取消考核"],
      责任单位已确认待第2次整改: ["第2次整改完成，待举报人确认", "完结-整改未完成，作为月度考评数据"],
      待举报人修正数据或取消: ["完结-举报人已取消", "举报后，待责任单位确认", "完结-自动取消"],
      整改完成后自动确认待公司管理员确认是否考核: ["完结-管理员认定考核", "完结-管理员取消考核"]
    },
    config_obj_: {
      举报后待责任单位确认: ["确认", "申诉"],//1.确定（是/否整改）2.申诉
      公司管理员判定所属责任单位待责任单位确认: ["确定"],//1.责任单位已确认，待整改2否整改（完结-责任单位已确认，作为月度考评数据）
      待公司管理员确定责任单位: ["同意申诉", "不同意申诉"],//1.待举报人修正数据或取消2.公司管理员判定所属责任单位，待责任单位确认
      责任单位已确认待整改: ["整改报完工", "未完成整改"],//整改报完工.未完成整改
      第1次整改完成待举报人确认: ["未完成整改", "已完成整改"],//1.驳回 2.完结
      第1次整改完成举报人不认可待重新整改: ["已整改，向公司申诉", "未完成整改"],//1.反驳2.二次确认
      第2次整改完成待举报人确认: ["未完成整改", "已完成整改"],//确定
      第1次整改结果有争议待公司管理员判定: ["认定考核", "取消考核"],//1.认定考核2.取消考核
      待公司管理员确认是否考核: ["认定考核", "取消考核"],//1.认定考核2.取消考核
      责任单位已确认待第2次整改: ["整改报完工", "未完成整改"],
      待举报人修正数据或取消: ["取消本次举报", "修正数据"],//"完结-举报人已取消","举报后，待责任单位确认","完结-自动取消"
      整改完成后自动确认待公司管理员确认是否考核: ["认定考核", "取消考核"]
    },
    config_arr1: ["举报后，待责任单位确认", "待公司管理员确定责任单位", "责任单位确认", "责任单位确认", "责任单位确认",],
    config_arr2: ["责任单位确认", "责任申诉判决", "责任单位确认", "责任单位确认", "责任单位确认", "责任单位确认",],
    current_status1: "",
    current_status2: [],
    current_btn: [],
    frock_number: "",
    baseUrl: "https://logisticsengineering.gree.com/container_manage_api/container_manage",
    list: [],
    detail_list: [],
    record_list: [],
    record_list1: [],
    record_list_total: 0,
    record_index: 1,
    record_show: false,
    page_size: 10,
    page: 1,
    total: 0,
    page_all: 0,
    all_total: 0,
    pan_total: 0,
    previewImageClick: false,
    show: false,
    show1: false,
    radio: null,
    radio1: null,
    data_arr: {},
    show2: false,
    show3: false,
    zgr_name: "",
    push_name: "",
    popup_show1: false,
    options1: [],
    status_show: true,
    reason: "",
    action_str: "",
    uploader: [],
    choose_img_btn_disabled: false,
    show4: false,
    show7: false,
    show11: false,
    show12: false,
    steps: [

    ],
    active: 0,
    radio11: null,
    radio22: null,
    show_ss: false,
    show33: false,
    record_show1: false,
    now_steps: {

    },
    disabled_status: false,
    required_status: false,
    radio33: null,
    detial_style: "border: 2px solid rgb(73, 70, 70);",
    activeNames: [],
    photo_list: [],
    task_row_data: {},
    activeNamesDetail: ['1'],
    onActiveChangeStep: [],
    task_id: "",
    inspect_show: true,
    deadline: "",
    back_flag: false,
    deadline_show: false,

    // field_style: " background-color: #333333; color:white"
  },
  // 时分的事件方法
  selectDateMinuteChange(e) {
    // 时分的事件方法
    let now_time = this.formatNowTime()
    if (e.detail.value < now_time) {
      return wx.showToast({
        title: '需求时间要求大于当前时间',
        icon: 'none'
      })
    } else {
      this.setData({
        deadline: e.detail.value
      })
    }





  },
  showProblem(e) {
    console.log(e);
    wx.showModal({
      content: e.currentTarget.dataset.row_data,

    })
  },
  onActiveDetailChange(event) {
    this.setData({
      activeNamesDetail: event.detail,
    });
  },
  onActiveChangeStep(event) {
    this.setData({
      activeNamesStep: event.detail,
    });
  },
  onChange8(event) {
    this.setData({
      activeNames: event.detail,
    });
  },


  // 分页
  onPageChange(e) {
    // console.log("xxx",e.detail.sonParam);
    let p = e.detail.sonParam
    this.setData({
      page: p,
    })
    this.getDataList()
  },

  // 获取数据
  getDataList(e) {

    let show_list = []
    show_list.push(e)
    let config_obj1 = this.data.config_obj
    let config_obj_ = this.data.config_obj_
    let reg = new RegExp("，", "g")
    let current_status = ""
    for (let i in show_list) {
      show_list[i].submit_time = this.GMTToStr(show_list[i].submit_time)
      current_status = show_list[i].status.replace(reg, "")
      show_list[i].current_status1 = show_list[i].status.replace(reg, "")
      show_list[i].current_status2 = config_obj1[show_list[i].current_status1]
      show_list[i].current_btn = config_obj_[show_list[i].current_status1]
      if (show_list[i].status == "举报后，待责任单位确认" || show_list[i].status == "公司管理员判定所属责任单位，待责任单位确认") {
        show_list[i].show_btn = false
      } else {
        show_list[i].show_btn = true

      }
      let live_record_length = show_list[i].live_record.length
      show_list[i].time1 = this.GMTToStr(show_list[i].live_record[live_record_length - 1].time)
    }

    this.setData({
      data_arr: show_list[0],
      list: show_list,
      previewImageClick: true,
      uploader: [],
      reason: ""


    })
    // console.log("x", self.data.current_status1, self.data.current_status2, self.data.current_btn,);

  },
  // 查看详情
  showDetail() {
    // wx.requestSubscribeMessage({
    //   tmplIds: ['Qq4EMCt24ZVzeR74sHCcdCgZyo7pus8Bf9knNoUHPpM'],

    // })
    let row = this.data.task_row_data.task
    if (row.status == "公司管理员判定所属责任单位，待责任单位确认") {
      this.setData({
        disabled_status: true,
        radio11: "1",
        show1: true,
      })
    }
    let list_ = []
    list_.push(row)
    let p_l = []
    for (let i in row.files) {
      let img_url = "https://logisticsengineering.gree.com/container_manage_api/container_manage/fs_download?file_id=" + row.files[i]
      p_l.push(img_url)
    }
    this.setData({
      detail_list: list_,
      show: true,
      data_arr: row,
      photo_list: p_l
    })
  },

  showDetail1(e) {
    // wx.requestSubscribeMessage({
    //   tmplIds: ['Qq4EMCt24ZVzeR74sHCcdCgZyo7pus8Bf9knNoUHPpM'],

    // })
    let row = e
    if (row.status == "公司管理员判定所属责任单位，待责任单位确认") {
      this.setData({
        disabled_status: true,
        radio11: "1",
      })
    }
    let list_ = []
    list_.push(row)
    let p_l = []
    for (let i in row.files) {
      let img_url = "https://logisticsengineering.gree.com/container_manage_api/container_manage/fs_download?file_id=" + row.files[i]
      p_l.push(img_url)
    }
    this.setData({
      detail_list: list_,
      data_arr: row,
      photo_list: p_l
    })
  },
  // 操作记录框关闭
  onClose6() {
    this.setData({
      record_show: false,
      record_index: 1,
      reason: "",
      uploader: []
    })
  },

  // 查看操作记录
  recordShow(e) {
    let live_record1 = e.live_record
    for (let i in live_record1) {
      live_record1[i].time = this.GMTToStr(live_record1[i].time)
    }
    let step = []
    for (let i in live_record1) {
      let obj = {
        // text: live_record1[i].action,
        desc: live_record1[i].involved_name + "，" + live_record1[i].time + "，" + live_record1[i].action,
        detail: live_record1[i]
      }
      step.push(obj)
    }
    console.log("11step", step);
    for (let i in step) {
      console.log("12313", step[i].action);
      if (step[i].detail.action == "问题提交" || step[i].detail.action == "第1次整改完成，举报人不认可，待重新整改" || step[i].detail.action == "待公司管理员确认是否考核") {
        step[i].desc = "举报人," + step[i].detail.time + "，" + step[i].detail.action

      }
    }
    console.log("step", step);

    this.setData({
      // record_show: true,
      steps: step,
      active: live_record1.length - 1

    })


  },
  // 点击记录步骤
  showStep(e) {
    if (e.detail == this.data.steps.length - 1) {
      this.setData({
        deadline_show: true
      })
    } else {
      this.setData({
        deadline_show: false
      })
    }

    this.setData({
      now_steps: this.data.steps[e.detail].detail,
      record_show1: true
    })

  },
  // 是否本单位责任选框
  onChange11(event) {
    console.log(event.detail);
    this.setData({
      radio11: event.detail
    })
    if (event.detail == "2") {
      console.log("xxxx");
      this.setData({

        show_ss: true,
        show33: false,
        show2: false,
        show1: false,
        deadline: "",
        reason: ""
      })
    } else if (event.detail == "1") {
      this.confirmBtn()
      this.setData({
        show_ss: false,
        // show2: true,
        reason: ""

      })
    }

  },

  // 是否整改
  onChange22(event) {
    console.log(event.detail);
    this.setData({
      radio22: event.detail
    })
    if (event.detail == 1) {
      this.setData({
        show33: true,
      })
    } else if (event.detail == 2) {
      this.setData({
        show33: false,
      })
    }

  },
  // 处理对话框关闭
  onClose() {
    this.setData({
      show: false,
      show1: false,
      deadline: "",
      reason: "",
      radio: null,
      radio11: null,
      radio22: null,
      radio33: null,
      data_arr: "",
      show_ss: false,
      show2: false,
      show4: false,
      show3: false,
      disabled_status: false,
      required_status: false,
      activeNames: [],
      zgr_name: "",
    })
  },
  // 处理对话框点确认
  onConfirm() {
    wx.requestSubscribeMessage({
      tmplIds: ['Qq4EMCt24ZVzeR74sHCcdCgZyo7pus8Bf9knNoUHPpM'],

    })
    console.log("123123", this.data.show);
    if (this.data.action_str == "举报后，待责任单位确认") {
      const row = this.data.data_arr
      row.flag = "flag2"
      wx.navigateTo({
        url: '/pages/wuliurongqiguanli/nav_handling/change_handing/change_handing',
        success(res) {
          res.eventChannel.emit('acceptDataFromOpenerPage', row)

        }
      })
      this.onClose()

    } else {
      // 1.判断是否申诉
      if (this.data.radio11 == 2) {
        console.log("申诉");
        // 判断说明是否填写
        if (!this.data.reason) {
          wx.showToast({
            title: '请填写申诉说明！',
            icon: 'error'
          })
        } else {
          let row = this.data.data_arr
          console.log("当前操作数据", row);
          if (row.status) {

          }
          let args1 = []
          if (row.live_record.length < 2) {
            args1 = []
          } else {
            args1 = row.live_record[1].args

          }

          let self = this;
          let url = self.data.baseUrl + "/update_problem"
          let data = {
            key: row._id,
            company: row.company,
            status: row.status,
            res_accurate: row.res_accurate,
            submitter: row.submitter,
            action: "待公司管理员确定责任单位",
            reason: self.data.reason,
            args: args1,
            files: [],
            deadline: this.data.deadline,
          }
          this.post(url, data).then(res => {
            if (res.code == 20000) {

              wx.showToast({
                title: res.msg,
              })
              setTimeout(function () {
                wx.reLaunch({
                  url: '/packageB/pages/package/task_manager/task_manager',
                })
              }, 2000)
            } else {
              wx.showToast({
                title: res.msg,
                icon: "error"
              })
            }
          }).catch(err => {
            wx.showToast({
              title: err.msg,
              icon: 'error'
            })
          })


        }

      } else if (this.data.radio11 == null && this.data.show4 == false && this.data.show1 == false) {
        wx.showToast({
          title: '请勾选执行步骤！',
          icon: 'none'
        })
      }


      if (this.data.show4 == true) {
        this.action()
      }

      if (this.data.show1 == true) {
        this.onConfirm1()
      }

    }



  },


  // 预览照片
  previewPhoto(e) {
    let img_url = "https://logisticsengineering.gree.com/container_manage_api/container_manage/fs_download?file_id=" + e.currentTarget.dataset.row_data
    console.log(img_url);


    let l = this.data.photo_list
    wx.previewImage({
      current: img_url,
      urls: l,
    })
  },
  // 预览照片
  previewPhoto1(e) {
    let img_url = "https://logisticsengineering.gree.com/container_manage_api/container_manage/fs_download?file_id=" + e.currentTarget.dataset.row_data
    console.log(img_url);
    let p_l = []

    for (let i in this.data.now_steps.files) {
      let img_url = "https://logisticsengineering.gree.com/container_manage_api/container_manage/fs_download?file_id=" + this.data.now_steps.files[i]
      p_l.push(img_url)
    }

    wx.previewImage({
      current: img_url,
      urls: p_l,
    })
  },
  // 说明情况/照片框弹出关闭
  onClose4() {
    this.setData({
      show4: false,
      required_status: false,

      uploader: [],
      reason: []
    })
  },


  // 说明情况/照片框弹出
  actionBtnShow(e) {
    console.log("当前操作数据", this.data.data_arr);
    console.log("当前按钮", e.detail);
    this.setData({
      radio33: e.detail,
    });
    if (e.detail == "整改报完工") {
      this.getPushUsers1(wx.getStorageSync('name'))

      this.setData({
        required_status: true,
      })
    } else {
      this.setData({
        required_status: false,
      })
    }

    let row = this.data.data_arr
    row.flag = "flag2"
    let index = row.current_btn.indexOf(e.detail)
    console.log("当前按钮下标", index);
    let action_str = row.current_status2[index]
    if (e.detail == "修正数据") {
      wx.navigateTo({
        url: '/pages/wuliurongqiguanli/nav_handling/change_handing/change_handing',
        success(res) {
          res.eventChannel.emit('acceptDataFromOpenerPage', row)

        }
      })

    }
    // if (e.detail == "同意申诉") {
    //   this.setData({
    //     zgr_name: row.live_record[0].involved
    //   })

    // }
    // if (e.detail == "不同意申诉") {
    //   this.setData({
    //     zgr_name: row.live_record[1].involved
    //   })

    // }
    this.setData({
      action_str: action_str
    })

    console.log("传过去的字符串", action_str);
    if (action_str == "责任单位已确认，待整改" || action_str == "责任单位已确认，待第2次整改") {
      this.setData({
        show4: false
      })
      this.confirmBtn()

    } else if (action_str == "第1次整改完成，举报人不认可，待重新整改") {
      let zgr_name1 = ""
      for (let i in row.live_record) {

        if (row.live_record[i].action == "责任单位已确认，待整改") {
          zgr_name1 = row.live_record[i].args[0]

        }
      }
      this.setData({
        show4: true,
        show1: false,
        deadline: "",
        zgr_name: zgr_name1,
        radio33: null,

      })

      // this.action(action_str)

    } else if (action_str == "举报后，待责任单位确认") {
      this.setData({
        show4: false,
        show1: false,
        deadline: "",
        show: false,


      })
    }
    // this.action(action_str)
    else {
      this.setData({
        show4: true,
        deadline: "",
        show1: false,

      })
    }



  },

  onChange33(e) {
    console.log(e.detail);
    this.setData({
      radio33: e.detail,
    });
  },

  // 操作按钮函数
  action() {
    const uploader = [...this.data.uploader];
    uploader.forEach((element, index) => {
      uploader[index] = element.url.split("=")[1];
    })
    console.log("整改/说明照片", uploader);
    let row = this.data.data_arr
    console.log("当前操作数据", row);

    let args1 = []
    console.log();
    if (this.data.zgr_name != "") {
      args1.push(this.data.zgr_name)
    }

    console.log("当前流程整改人", args1);

    if (this.data.reason == "") {
      wx.showToast({
        title: '请填写说明情况！',
        icon: 'error'
      })
    } else {
      if (this.data.action_str == "第2次整改完成，待举报人确认" || this.data.action_str == "第1次整改完成，待举报人确认") {
        if (uploader.length == 0) {
          console.log("asdasd");
          wx.showToast({
            title: '请上传照片！',
            icon: 'error'
          })
        } else {

          let self = this;
          let url = self.data.baseUrl + "/update_problem"
          let data = {
            key: row._id,
            company: row.company,
            status: row.status,
            res_accurate: row.res_accurate,
            submitter: row.submitter,
            action: self.data.action_str,
            reason: self.data.reason,
            args: args1,
            files: uploader,
            deadline: this.data.deadline
          }
          this.post(url, data).then(res => {
            if (res.code == 20000) {

              wx.showToast({
                title: res.msg,
              })
              setTimeout(function () {
                wx.reLaunch({
                  url: '/packageB/pages/package/task_manager/task_manager',
                })
              }, 2000)
            } else {
              wx.showToast({
                title: res.msg,
                icon: "error"
              })
            }
          }).catch(err => {
            wx.showToast({
              title: err.msg,
              icon: 'error'
            })
          })
        }
      } else {

        let self = this;
        let url = self.data.baseUrl + "/update_problem"
        let data = {
          key: row._id,
          company: row.company,
          status: row.status,
          res_accurate: row.res_accurate,
          submitter: row.submitter,
          action: self.data.action_str,
          reason: self.data.reason,
          args: args1,
          files: uploader,
          deadline: this.data.deadline
        }
        this.post(url, data).then(res => {
          if (res.code == 20000) {

            wx.showToast({
              title: res.msg,
            })
            setTimeout(function () {
              wx.reLaunch({
                url: '/packageB/pages/package/task_manager/task_manager',
              })
            }, 2000)
          } else {
            wx.showToast({
              title: res.msg,
              icon: "error"
            })
          }
        }).catch(err => {
          wx.showToast({
            title: err.msg,
            icon: 'error'
          })
        })


      }


    }


  },

  // 申诉
  action1() {
    this.setData({
      show7: true
    })
  },

  // 点击确定按钮弹出对话框
  confirmBtn() {
    this.setData({
      radio: null,
      show1: true
    })
  },
  // 是否整改选择框
  onChange(event) {
    console.log(event.detail);
    this.setData({
      radio: event.detail,
    });
    if (event.detail == 1) {
      this.setData({
        show2: true,
        radio1: null
      })
    } else {
      this.setData({
        show2: false
      })
    }
  },

  // 是否转发其他人整改对话框
  onChange1(event) {
    console.log("11", event.detail);
    this.setData({
      radio1: event.detail,
    });
    if (event.detail == 2) {
      this.setData({
        zgr_name: wx.getStorageSync('_id'),
        show3: false,
      })

      // console.log("cc", this.data.zgr_name);
    } else {
      this.setData({
        zgr_name: "",
        show3: true,
      })
    }
  },

  // 通过名称查推荐人
  getPushUsers1(e) {
    let self = this;
    let url = self.data.baseUrl + "/get_push_users"
    let data = {
      name: e,

    }
    this.post(url, data).then(res => {
      if (res.code == 20000) {
        self.setData({
          zgr_name: res.data[0]._id
        })
        console.log("当前整改人", self.data.zgr_name);
        // wx.showToast({
        //   title: res.msg,
        // })

      } else {


      }
    }).catch(err => {

      console.log(err);
    })
  },
  // 通过名称查推荐人
  getPushUsers(e) {
    let self = this;
    console.log(e);
    let url = self.data.baseUrl + "/get_push_users"
    let data = {
      name: e.detail,

    }
    this.post(url, data).then(res => {
      if (res.code == 20000) {
        let list_ = res.data
        self.setData({
          options1: list_
        })
        // wx.showToast({
        //   title: res.msg,
        // })

      } else {
        wx.showToast({
          title: res.msg,
          icon: "error"
        })

      }
    }).catch(err => {

      wx.showToast({
        title: err.msg,
        icon: 'none'
      })
    })
  },
  // 点击--确定推进人--输入框
  onClick1(event) {
    // event.detail 为当前输入的值
    // console.log(event.detail);
    this.setData({
      popup_show1: true
    })
  },
  // 选择--确定推进人--输入框关闭
  onClose1() {
    this.setData({ popup_show1: false });
  },
  // 确定推进人
  onradioChange2(e) {
    console.log("123123", e.detail);
    this.setData({
      zgr_name: e.detail._id,
      zgr_name1: e.detail.name + "-" + e.detail.department,
      popup_show1: false

    })
  },
  // 是否整改对话框关闭
  onClose2() {
    this.setData({
      deadline: "",
      show1: false,
      show2: false,
      show3: false,
      radio1: null,
      uploader: [],
      reason: [],
      radio11: null


    })
  },

  // 责任单位详情
  detailShow(e) {
    console.log(e.currentTarget.dataset.row_data);
    wx.showToast({
      title: e.currentTarget.dataset.row_data,
      icon: 'none'
    })
  },
  // 整改方法函数
  onConfirm1() {
    console.log("Xxx", this.data.radio);
    const uploader = [...this.data.uploader];
    uploader.forEach((element, index) => {
      uploader[index] = element.url.split("=")[1];
    })

    console.log("整改/说明照片", uploader);


    let key = this.data.radio
    let row = this.data.data_arr
    console.log("当前操作数据", row);

    if (this.data.radio != null) {
      if (key == 2) {
        console.log("是否整改框-选“否”");

        if (this.data.reason == "") {
          wx.showToast({
            title: '请填写说明情况',
            icon: 'error'
          })

        } else {

          let self = this;
          let url = self.data.baseUrl + "/update_problem"

          let data = {
            key: row._id,
            company: row.company,
            status: row.status,
            res_accurate: row.res_accurate,
            submitter: row.submitter,
            action: "完结-责任单位已确认，作为月度考评数据",
            reason: self.data.reason,
            args: [],
            files: uploader,
            deadline: this.data.deadline
          }
          this.post(url, data).then(res => {
            if (res.code == 20000) {

              wx.showToast({
                title: res.msg,
              })
              setTimeout(function () {
                wx.reLaunch({
                  url: '/packageB/pages/package/task_manager/task_manager',
                })
              }, 2000)
            } else {
              wx.hideLoading();
              wx.showToast({
                title: res.msg,
                icon: "error"
              })
            }
          }).catch(err => {
            wx.hideLoading();
            wx.showToast({
              title: err.msg,
              icon: 'error'
            })
          })

        }



      } else {

        console.log("整改框选“是”");
        if (this.data.reason == "" || this.data.radio1 == null) {
          // Toast()
          wx.showToast({
            title: '说明/是否转发其他人整改不能为空',
            icon: 'none'
          })

        } else {

          let self = this;
          let action1 = self.data.action_str
          console.log("3123123", row.status);
          console.log("1111第二次确认责任", action1);
          if (row.status == "举报后，待责任单位确认" || row.status == "公司管理员判定所属责任单位，待责任单位确认") {
            console.log("1111");
            action1 = "责任单位已确认，待整改"

          }
          console.log("第二次确认责任", action1);
          let url = self.data.baseUrl + "/update_problem"
          let args1 = []
          if (this.data.zgr_name.length != 0) {
            args1.push(this.data.zgr_name)
          }
          let data = {
            key: row._id,
            company: row.company,
            status: row.status,
            res_accurate: row.res_accurate,
            submitter: row.submitter,
            action: action1,
            reason: self.data.reason,
            args: args1,
            files: uploader,
            deadline: this.data.deadline
          }
          this.post(url, data).then(res => {
            if (res.code == 20000) {

              wx.showToast({
                title: res.msg,
              })
              setTimeout(function () {
                wx.reLaunch({
                  url: '/packageB/pages/package/task_manager/task_manager',
                })
              }, 2000)
            } else {
              wx.showToast({
                title: res.msg,
                icon: "error"
              })
            }
          }).catch(err => {
            wx.showToast({
              title: err.msg,
              icon: 'error'
            })
          })

        }

      }
    } else {
      wx.showToast({
        title: '请选择是否整改！',
        icon: 'error'
      })

    }



  },
  // 整改报完工   
  bwgBtn() {

    let row = this.data.data_arr
    console.log("当前操作数据", row);
    console.log("整改报完工");
    let self = this;
    let url = self.data.baseUrl + "/update_problem"
    let data = {
      key: row._id,
      company: row.company,
      status: row.status,
      res_accurate: row.res_accurate,
      submitter: row.submitter,
      action: "第1次整改完成，待举报人确认",
      reason: "",
      args: row.live_record[1].args,
      files: row.files,
      deadline: this.data.deadline
    }
    this.post(url, data).then(res => {
      if (res.code == 20000) {

        setTimeout(function () {
          wx.reLaunch({
            url: '/packageB/pages/package/task_manager/task_manager',
          })
        }, 2000)
        wx.showToast({
          title: res.msg,
        })
      } else {
        wx.showToast({
          title: res.msg,
          icon: "error"
        })
      }
    }).catch(err => {
      wx.showToast({
        title: err.msg,
        icon: 'none'
      })
    })

  },
  // 整改报完工   
  callBackBtn() {
    wx.showModal({
      title: '确认撤销此单据？',
      content: '',
      complete: (res) => {
        if (res.cancel) {

        }

        if (res.confirm) {
          let row = this.data.data_arr
          let self = this;
          let url = self.data.baseUrl + "/recall_process_problem"
          let data = {
            key: row._id,
            company: row.company,
            status: row.status,
            res_accurate: row.res_accurate,
            submitter: row.submitter,
            reason: "",
          }
          this.post(url, data).then(res => {
            if (res.code == 20000) {

              setTimeout(function () {
                wx.reLaunch({
                  url: '/packageB/pages/package/task_manager/task_manager',
                })
              }, 2000)
              wx.showToast({
                title: res.msg,
              })
            } else {
              wx.showToast({
                title: res.msg,
                icon: "error"
              })
            }
          }).catch(err => {
            wx.showToast({
              title: err.msg,
              icon: 'none'
            })
          })
        }
      }
    })



  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let self = this
    const eventChannel = this.getOpenerEventChannel()
    // 监听acceptDataFromOpenerPage事件，获取上一页面通过eventChannel传送到当前页面的数据
    eventChannel.on('toHandle', function (data) {
      console.log("传过来的数据", data)
      self.getDataList(data.task)
      self.showDetail1(data.task)
      self.recordShow(data.task)
      if (data.flag == "done") {
        self.setData({
          inspect_show: false,
        })
      }




      self.setData({
        task_row_data: data,
        task_id: data.task_id,
        business_content: data.business_content,
        creator_name: data.creator_name,
        lastProcessUser: data.lastProcessUser,
        lastProcessAction: data.lastProcessAction,
        data_arr: data.task


      })


    })
    eventChannel.on('showDetail', function (data) {
      console.log("传过来的数据", data)
      self.getDataList(data.task)
      self.showDetail1(data.task)
      self.recordShow(data.task)
      if (data.task.live_record.length == 1) {
        self.setData({
          back_flag: true,

        })
      }
      self.setData({
        inspect_show: false,
        task_row_data: data,
        task_id: data.task_id,
        business_content: data.business_content,
        creator_name: data.creator_name,
        lastProcessUser: data.lastProcessUser,
        lastProcessAction: data.lastProcessAction,
        data_arr: data.task


      })


    })
  },
  // 65f14411b2134c8da2962426
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({
      minDate: new Date(),
      currentDate: new Date(),
    })
    // if (this.data.previewImageClick == false) {
    //   this.getDataList()

    // }

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },

  // 照片选取
  try_upload(e) {
    const self = this;
    // 关闭照片选取
    self.setData({
      choose_img_btn_disabled: true
    });
    // 确定还有张图片可以选择
    const count = 3 - this.data.uploader.length;
    wx.chooseMedia({
      count: count,
      mediaType: ['image'],
      sourceType: ['album', 'camera'],
      maxDuration: 30,
      camera: 'back',
      success(res) {
        const myUploadFiles = res.tempFiles.map(tempFile => {
          const tempFilePath = tempFile.tempFilePath;
          return self.myUploadFile(tempFilePath);
        });
        wx.showLoading({
          title: '开始上传。。。',
        })
        Promise.all(myUploadFiles).then(file_ids => {
          wx.hideLoading();
          // 处理UI
          console.log(file_ids);
          const uploader = self.data.uploader;
          const new_uploader = uploader.concat(file_ids.map(file_id => {
            return {
              url: baseUrl + "fs_download?file_id=" + file_id,
              isImage: true
            };
          }));
          self.setData({
            uploader: new_uploader
          })
          if (self.data.uploader.length < 3) {
            self.setData({
              choose_img_btn_disabled: false
            });
          }
          wx.showToast({
            title: '上传成功！',
          });

        }).catch(msg => {
          wx.hideLoading();
          if (self.data.uploader.length < 3) {
            self.setData({
              choose_img_btn_disabled: false
            })
          }
          wx.showToast({
            title: msg,
            icon: "error"
          })
          console.log(msg);
        });
      },
      fail() {
        if (self.data.uploader.length < 3) {
          self.setData({
            choose_img_btn_disabled: false
          })
        }
      }
    })
  },
  myUploadFile(file) {
    return new Promise((resolve, reject) => {
      wx.uploadFile({
        url: "https://logisticsengineering.gree.com/container_manage_api/container_manage/fs_upload",
        filePath: file,
        name: 'file',
        formData: {},
        success(res) {
          const result = JSON.parse(res.data);
          console.log(result);
          wx.hideLoading();
          if (result.code == 20000) {
            resolve(result.data.file_id);
          } else {
            reject(msg);
          }

        },
        fail() {
          reject("未知错误446");
        }
      })
    });
  },
  handle_delete(e) {
    const index = e.detail.index;
    const file = this.data.uploader[index];
    const file_id = file.url.split("=")[1];
    const uploader = this.data.uploader;
    const self = this;
    this.post(baseUrl + 'fs_delete', { file_id }).then((res) => {
      const code = res["code"];
      if (code == 20000) {
        uploader.splice(index, 1);
        self.setData({
          choose_img_btn_disabled: false
        })
        console.log("uploader", uploader)
        self.setData({
          uploader
        });
      } else {
        wx.showToast({
          title: result.msg,
          icon: "error"
        })
      }
    }).catch(() => {
      console.log("error");
    })
  },
})